/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2023-04-09     Administrator       the first version
 */
#ifndef APPLICATIONS_DEV_SENSORS_H_
#define APPLICATIONS_SENSORS_H_


#define SGP30_ADDR                      0x58
#define SHT20_ADDR                      0x40


#define ERROR_I2C_TIMEOUT                     998
#define ERROR_BAD_CRC                         999

#define TRIGGER_TEMP_MEASURE_HOLD             0xE3
#define TRIGGER_HUMD_MEASURE_HOLD             0xE5
#define TRIGGER_TEMP_MEASURE_NOHOLD           0xF3
#define TRIGGER_HUMD_MEASURE_NOHOLD           0xF5
#define WRITE_USER_REG                        0xE6
#define READ_USER_REG                         0xE7
#define SOFT_RESET                            0xFE
#define USER_REGISTER_RESOLUTION_MASK         0x81
#define USER_REGISTER_RESOLUTION_RH12_TEMP14  0x00
#define USER_REGISTER_RESOLUTION_RH8_TEMP12   0x01
#define USER_REGISTER_RESOLUTION_RH10_TEMP13  0x80
#define USER_REGISTER_RESOLUTION_RH11_TEMP11  0x81
#define USER_REGISTER_END_OF_BATTERY          0x40
#define USER_REGISTER_HEATER_ENABLED          0x04
#define USER_REGISTER_DISABLE_OTP_RELOAD      0x02

#define MAX_WAIT                              100
#define DELAY_INTERVAL                        10
#define SHIFTED_DIVISOR                       0x988000
#define MAX_COUNTER                           (MAX_WAIT/DELAY_INTERVAL)


rt_err_t i2c_bus_init(void);
rt_err_t dev_sgp30_init(void);
void sht20_check(void);
rt_err_t dev_sgp30_read(uint16_t* CO2_Value, uint16_t* TVOC_Vlaue);
void read_temp_humi(float *cur_temp, float *cur_humi);
void dev_adc_channel_init(void);
void adc_read_channels(float* value, uint32_t channel);
int adc_read_channels_src( uint32_t channel);
int get_gp2y10_value(void);





#endif /* APPLICATIONS_DEV_SENSORS_H_ */
